import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';

import { BGEEmbeddings } from './embeddings';

@Injectable()
export class EmbeddingsService {
  embeddings: BGEEmbeddings;

  constructor(readonly configService: ConfigService) {
    const apiKey = configService.get<string>('EMBEDDING_API_KEY');
    const apiUrl = configService.get<string>('EMBEDDING_API_URL');
    const model = configService.get<string>('EMBEDDING_MODEL');

    if (!apiKey || !apiUrl || !model) {
      throw new Error('向量存储库初始化失败，缺少必要的环境变量');
    }

    this.embeddings = new BGEEmbeddings(apiKey, apiUrl, model);
  }
}
